//package jp.sourceforge.talisman.mds.distance;
//
///*
// * $Id: NearestNeighborDistanceCalculatorTest.java,v 1.1 2009/09/12 05:06:08 weiwei Exp $
// */
//
//import jp.sourceforge.talisman.mds.Item;
//import jp.sourceforge.talisman.mds.cluster.Cluster;
//
//import org.junit.Assert;
//import org.junit.Before;
//import org.junit.Test;
//
///**
// * 
// * @author Haruaki Tamada
// * @version $Revision: 1.1 $ 
// */
//public class NearestNeighborDistanceCalculatorTest{
//    private ClusterDistanceCalculator distance;
//
//    private Cluster cluster1;
//    private Cluster cluster2;
//    private Cluster cluster3;
//
//    @Before
//    public void initialize() throws Exception{
//        DistanceCalculatorFactory factory = DistanceCalculatorFactory.getInstance();
//        distance = factory.getClusterDistanceCalculator(
//            ClusterDistanceAlgorithm.NEAREST_NEIGHBOR_METHOD,
//            ItemDistanceAlgorithm.SQUARED_EUCLIDEAN_DISTANCE
//        );
//
//        cluster1 = new Cluster();
//        cluster2 = new Cluster();
//        cluster3 = new Cluster();
//
//        // median = 1, 1
//        // median(cluster1, cluster2) = 16/7, 16/7
//        cluster1.addItem(new Item("item1", new double[] { 2, 2, }));
//        cluster1.addItem(new Item("item2", new double[] { 0, 2, }));
//        cluster1.addItem(new Item("item3", new double[] { 2, 0, }));
//        cluster1.addItem(new Item("item4", new double[] { 0, 0, }));
//
//        // median = 4, 4
//        cluster2.addItem(new Item("item5", new double[] { 3, 3, }));
//        cluster2.addItem(new Item("item6", new double[] { 4, 6, }));
//        cluster2.addItem(new Item("item7", new double[] { 5, 3, }));
//
//        // median = 8, 1
//        cluster3.addItem(new Item("item8", new double[] { 7, 0, }));
//        cluster3.addItem(new Item("item9", new double[] { 9, 2, }));
//    }
//
//    @Test
//    public void testBasic(){
//        Assert.assertEquals(Math.sqrt(2), distance.calculate(cluster1, cluster2));
//        Assert.assertEquals(Math.sqrt(25), distance.calculate(cluster1, cluster3));
//        Assert.assertEquals(Math.sqrt(13), distance.calculate(cluster2, cluster3));
//
//        Assert.assertEquals(ClusterDistanceAlgorithm.NEAREST_NEIGHBOR_METHOD, distance.getAlgorithm());
//    }
//
//    @Test
//    public void testBasic2(){
//        distance = new NearestNeighborClusterDistanceCalculator(ItemDistanceAlgorithm.SQUARED_EUCLIDEAN_DISTANCE);
//        
//        Assert.assertEquals(Math.sqrt(2), distance.calculate(cluster1, cluster2));
//        Assert.assertEquals(Math.sqrt(25), distance.calculate(cluster1, cluster3));
//        Assert.assertEquals(Math.sqrt(13), distance.calculate(cluster2, cluster3));
//    }
//
//    @Test
//    public void testUpdate(){
//        Cluster clusetr12 = new Cluster();
//        for(Item item: cluster1) clusetr12.addItem(item);
//        for(Item item: cluster2) clusetr12.addItem(item);
//        
//        Assert.assertEquals(distance.calculate(clusetr12, cluster3), 
//            distance.update(cluster1, cluster2, cluster3, Math.sqrt(2), Math.sqrt(25), Math.sqrt(13)));
//    }
//}
